using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;

public class UI_MerchantSlot : UI_ItemSlot
{
    private Inventory_Merchant merchant;
    public void SetupMerchantSlot(Inventory_Merchant merchant)
    {
        this.merchant = merchant;
    }
    public override void OnPointerDown(PointerEventData eventData)
    {
        if (itemInSlot == null)
            return;

        bool isClickRightButton = eventData.button == PointerEventData.InputButton.Right;
        bool isClickLeftButton = eventData.button == PointerEventData.InputButton.Left;

        if (slotType == SlotType.PlayerInventorySlot)
        {
            if (isClickRightButton)
            {
                bool isClickCtrl = Input.GetKey(KeyCode.LeftControl);
                merchant.TrySellItem(itemInSlot, isClickCtrl);
            }
            else if (isClickLeftButton)
                base.OnPointerDown(eventData);
        }
        else if (slotType == SlotType.MerchantSlot)
        {
            if (isClickLeftButton)
            {
                bool isClickCtrl = Input.GetKey(KeyCode.LeftControl);
                merchant.TryBuyItem(itemInSlot, isClickCtrl);
            }
            else
                return;
        }
        itemToolTip.ShowToolTip(false, null);
    }
    public override void OnPointerEnter(PointerEventData eventData)
    {
        if (itemInSlot == null)
            return;
        if (slotType == SlotType.MerchantSlot)
            itemToolTip.ShowToolTip(true, rect, itemInSlot, true, true);
        else
            itemToolTip.ShowToolTip(true, rect, itemInSlot, false, true);
    }
}
